#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 10
void Countsort(int* a, int n)
{
	int max = a[0], min = a[0];
	for (int i = 0; i < n; i++)
	{
		if (a[i] > max)
			max = a[i];
		if (a[i] < min)
			min = a[i];
	}
	int range = max - min + 1;
	int* count = (int*)malloc(sizeof(int) * range);
	memset(count, 0, sizeof(int) * range);
	for (int i = 0; i < n; i++)
	{
		count[a[i] - min]++;
	}
	int j = 0;
	for (int i = 0; i < range; ++i)
	{
		while (count[i]--)
		{
			a[j++] = i + min;
		}
	}
}

int main()
{
	int a[N] = { 0 };
	for (int i = 0; i < N; i++)
	{
		a[i] = rand() % 100;
	}
	Countsort(a, sizeof(a) / sizeof(int));
	for (int i = 0; i < N; i++)
	{
		printf("%d ", a[i]);
	}
	return 0;
}


